package com.atguigu.spring.listener;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * 现示自定义事件发布器
 * @author mi
 * @time 2021/4/19 0:29
 */
@Component
public class AppEventPublisher implements ApplicationEventPublisherAware {
	ApplicationEventPublisher applicationEventPublisher;
	/**
	 * Set the ApplicationEventPublisher that this object runs in.
	 * <p>Invoked after population of normal bean properties but before an init
	 * callback like InitializingBean's afterPropertiesSet or a custom init-method.
	 * Invoked before ApplicationContextAware's setApplicationContext.
	 *
	 * @param applicationEventPublisher event publisher to be used by this object
	 */
	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
		this.applicationEventPublisher = applicationEventPublisher;
	}

	public void publish(Object event) {
		applicationEventPublisher.publishEvent(event);
	}

}
